package chapter03

import org.apache.spark.{SparkConf, SparkContext}

object Test10_FlatMapAndGlom {
  def main(args: Array[String]): Unit = {
    val pay = new SparkConf().setMaster("local[*]").setAppName("Flat")
    val sc = new SparkContext(pay)
    val value = sc.makeRDD(List(List(1, 2, 3), List(4, 5, 6)))
    println(value.flatMap(e=>e).collect().toList)
    val value1 = sc.makeRDD(List(1, 2, 3, 4, 5, 6, 7, 8, 9), 3)
    val value2 = value1.glom()
    println(value2.map(e=>e.toList).collect().mkString("Array(", ", ", ")"))
    //计算每个分区的最大值
    val value3 = value2.map(e => e.max)
    println(value3.collect().toList)
    println(value1.mapPartitions(e=>Iterator(e.max)).collect().toList)
  }
}
